package org.example.oss.controller;

import io.swagger.annotations.Api;
import org.example.ResultCode.R;
import org.example.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@Api(description="阿里云文件管理")
@RestController
@RequestMapping("/eduoss/fileoss")
@CrossOrigin //解决跨域问题
public class OssController {
    @Autowired
    private OssService ossService;

    //上传头像的方法
    @PostMapping
    public R uploadOssFile(
            MultipartFile file) { //MultipartFile file用来得到用户上传的文件
        //上传文件到oss,并得到文件的url
        String url = ossService.uploadFileAvatar(file);
        return R.ok().data("url",url);
    }
}
